﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Resources;
using System.Globalization;

namespace LPV_POS.mh_pos
{
    public partial class mh_banhang2_TachGopPhieu : DevExpress.XtraEditors.XtraForm
    {
        CultureInfo culture;
        string BH_PHIEU_MA = "";
        string BH_PHIEU_MA2 = "";
        DataTable tbDeleteLeft = null;
        DataTable tbDeleteRight = null;

        #region "Muti language"
        private void SetLanguage_banhang(string cultureName)
        {
            try
            {
                culture = CultureInfo.CreateSpecificCulture(cultureName);
                ResourceManager rm = new ResourceManager("LPV_POS.Muti_language.MyResource", typeof(mh_banhang2_TachGopPhieu).Assembly);
                bton_thuchien_1.Text = rm.GetString("dongy", culture);
                bton_thoat_1.Text = rm.GetString("thoat", culture);
                lbel_tencongty.Text = rm.GetString("tachgopphieu", culture);
                col_OBJNAME1.Caption = rm.GetString("mon", culture);
                col_SO_LUONG1.Caption = rm.GetString("soluong", culture);
                col_OBJNAME2.Caption = rm.GetString("mon", culture);
                col_SO_LUONG2.Caption = rm.GetString("soluong", culture);
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.ToString(), "Note");
            }

        }

        #endregion

        #region "   mh_banhang2_TachGopPhieu"
        public mh_banhang2_TachGopPhieu(string _DM_BAN_MA)
        {
            InitializeComponent();
            culture = CultureInfo.CurrentCulture;
            // -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -==
            // -== -== -== -== -== -== -== -== -==  DM_KHUVUC2
            // -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -==
            string sSQL = "SELECT * FROM BH_PHIEU_TMP WHERE DM_BAN_MA LIKE '" + _DM_BAN_MA + "' ORDER BY OBJID";
            thuvien othuvien = new thuvien();
            DataTable tbPHIEU = othuvien.SP_SelectDataTable("sp_executesql", new string[] { "@sSQL" }, new object[] { sSQL });
            DataTable tbPHIEUCOPY = tbPHIEU.Copy();
            DataRow drcopy = tbPHIEUCOPY.NewRow();
            drcopy["OBJID"] = " -- Phiếu mới--";
            drcopy["TONG_TIEN"] = 0;
            tbPHIEUCOPY.Rows.InsertAt(drcopy, 0);

            othuvien.f_showdataoncombox(cboPhieuLeft, tbPHIEU, "OBJID", "OBJID");
            othuvien.f_showdataoncombox(cboPhieuRight, tbPHIEUCOPY, "OBJID", "OBJID");
            
            //PHIEU_A
            if (tbPHIEU.Rows.Count > 0)
                BH_PHIEU_MA = tbPHIEU.Rows[0]["OBJID"] + "";
            
            //PHIEU_B
            if (tbPHIEUCOPY.Rows.Count > 2)//> 2 PHIEU
                BH_PHIEU_MA2 = tbPHIEUCOPY.Rows[2]["OBJID"] + "";
            else if (tbPHIEUCOPY.Rows.Count > 1)//PHIEU MOI
                BH_PHIEU_MA2 = tbPHIEUCOPY.Rows[0]["OBJID"] + "";

            bLoadForm = true;
        }
        #endregion

        #region "   ShowData_tbLeft"
        void ShowData_tbLeft()
        {
            string sSQL = "SELECT a.OBJID, a.MAHH, a.SO_LUONG, a.DON_GIA, a.CHIETKHAU_PHANTRAM, a.CHIETKHAU_TIEN, a.VAT_PHANTRAM, a.VAT_TIEN, a.THANH_TIEN, " +
                          "     OBJNAME = (CASE WHEN A.MAHH LIKE 'Tien_Gio' THEN N'Tiền Giờ' ELSE b.OBJNAME END), a.GHI_CHU, a.NGAY_TINH_GIO " +
                          "FROM BH_PHIEU_CT_TMP a " +
                          "     LEFT JOIN DM_HH b ON a.MAHH = b.OBJID " +
                          "WHERE BH_PHIEU_MA LIKE '" + BH_PHIEU_MA + "' "
                          ;

            DataTable tbMain1 = new thuvien().SP_SelectDataTable("sp_executesql", new string[] { "@sSQL" }, new object[] { sSQL });
            gridControlLeft.DataSource = tbMain1;
        }
        #endregion

        #region "   ShowData_tbRight"
        void ShowData_tbRight()
        {
            string sSQL = "SELECT a.OBJID, a.MAHH, a.SO_LUONG, a.DON_GIA, a.CHIETKHAU_PHANTRAM, a.CHIETKHAU_TIEN, a.VAT_PHANTRAM, a.VAT_TIEN, a.THANH_TIEN, " +
                          "     OBJNAME = (CASE WHEN A.MAHH LIKE 'Tien_Gio' THEN N'Tiền Giờ' ELSE b.OBJNAME END), a.GHI_CHU, a.NGAY_TINH_GIO " +
                          "FROM BH_PHIEU_CT_TMP a " +
                          "     LEFT JOIN DM_HH b ON a.MAHH = b.OBJID " +
                          "WHERE BH_PHIEU_MA LIKE '" + BH_PHIEU_MA2 + "' "
                          ;
            DataTable tbMain2 = new thuvien().SP_SelectDataTable("sp_executesql", new string[] { "@sSQL" }, new object[] { sSQL });
            gridControlRight.DataSource = tbMain2;
        }
        #endregion

        #region "   mh_banhang1_TachGopBan_Load"
        Boolean bLoadForm = false;
        private void mh_banhang1_TachGopBan_Load(object sender, EventArgs e)
        {
            cpublic ocpublic = new cpublic();
            string str_lang = ocpublic.Registry_Get("mh_main_lang");
            if (str_lang == "")
                str_lang = "vi-VN";
            SetLanguage_banhang(str_lang);

            cboPhieuLeft._SetselectedID(BH_PHIEU_MA);
            cboPhieuRight._SetselectedID(BH_PHIEU_MA2);
        }
        #endregion

        #region "   btnThoat_Click"
        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Dispose();
        }
        #endregion

        #region "   btnThucHien_Click"
        private void btnThucHien_Click(object sender, EventArgs e)
        {
            if (cboPhieuRight.SelectedIndex == 0)
                BH_PHIEU_MA2 = cboPhieuRight._GetselectedID();
            if (BH_PHIEU_MA2 != "")
            {
                thuvien othuvien = new thuvien();
                int irt = -1;

                this.RefreshTable();

                DataTable tbLeftCbo = (DataTable)cboPhieuLeft.Datasource;
                #region "   tbLeftCbo"//BH_PHIEU_TMP
                DataRow drLeft = null;
                if (tbLeftCbo.Select("OBJID LIKE '" + BH_PHIEU_MA + "'").Length > 0)
                {
                    drLeft = tbLeftCbo.Select("OBJID LIKE '" + BH_PHIEU_MA + "'")[0];
                    string ioutput="@ioutput";
                    new cpublic().get_ngay_lam_viec();//--------25/06/2012---------------
                    irt = othuvien.SP_Update("sp_mh_banhang",
                                          new string[] { "@flag", "@OBJID", "@DM_BAN_MA", "@NGUOI_LAP","@CA", "@NGAY_GIO_VAO", "@NGAY_GIO_RA", 
                                                         "@TINH_TIEN_THEO_NGAY", "@TIEN_GIO", "@THANH_TIEN", "@CK_PHANTRAM", "@CK_TIEN", 
                                                         "@VAT_PHANTRAM", "@VAT_TIEN", "@TTIEP_PHANTRAM", "@TTIEP_TIEN", "@PHU_THU_PHANTRAM", 
                                                         "@PHU_THU", "@TONG_TIEN", "@GHI_CHU" , "@NGAY_LAM_VIEC" },
                                          new object[] { 17, drLeft["OBJID"], drLeft["DM_BAN_MA"], drLeft["NGUOI_LAP"], drLeft["CA"], drLeft["NGAY_GIO_VAO"], drLeft["NGAY_GIO_RA"], 
                                                         drLeft["TINH_TIEN_THEO_NGAY"], drLeft["TIEN_GIO"], drLeft["THANH_TIEN"], drLeft["CK_PHANTRAM"], drLeft["CK_TIEN"], 
                                                         drLeft["VAT_PHANTRAM"], drLeft["VAT_TIEN"], drLeft["TTIEP_PHANTRAM"], drLeft["TTIEP_TIEN"], drLeft["PHU_THU_PHANTRAM"], 
                                                         drLeft["PHU_THU"], drLeft["TONG_TIEN"], drLeft["GHI_CHU"] , Variable.ngay_lamviec},
                                                         ref ioutput
                                                         );
                    if (drLeft["OBJID"] + "" == "" || drLeft["OBJID"] + "" == "-1")
                        drLeft["OBJID"] = ioutput;
                }
                #endregion

                DataTable tbRightCbo = (DataTable)cboPhieuRight.Datasource;
                #region "   tbRightCbo"//BH_PHIEU_TMP
                DataRow drRight = null;
                if (tbRightCbo.Select("OBJID LIKE '" + BH_PHIEU_MA2 + "'").Length > 0)
                {
                    drRight = tbRightCbo.Select("OBJID LIKE '" + BH_PHIEU_MA2 + "'")[0];
                    if (BH_PHIEU_MA2.IndexOf("--") >= 0)
                        drRight["NGAY_GIO_VAO"] = Variable.ngay_gio_hienhanh;// Variable.ngay_gio_hienhanh;
                    string ioutput="@ioutput";
                    new cpublic().get_ngay_lam_viec();//--------25/06/2012---------------
                    irt = othuvien.SP_Update("sp_mh_banhang",
                                       new string[] { "@flag", "@OBJID", "@DM_BAN_MA", "@NGUOI_LAP","@CA", "@NGAY_GIO_VAO", "@NGAY_GIO_RA", 
                                                      "@TINH_TIEN_THEO_NGAY", "@TIEN_GIO", "@THANH_TIEN", "@CK_PHANTRAM", "@CK_TIEN", 
                                                      "@VAT_PHANTRAM", "@VAT_TIEN", "@TTIEP_PHANTRAM", "@TTIEP_TIEN", "@PHU_THU_PHANTRAM", 
                                                      "@PHU_THU", "@TONG_TIEN", "@GHI_CHU", "@NGAY_LAM_VIEC" },
                                       new object[] { 17, drRight["OBJID"], drRight["DM_BAN_MA"], drRight["NGUOI_LAP"], drRight["CA"], drRight["NGAY_GIO_VAO"], drRight["NGAY_GIO_RA"], 
                                                      drRight["TINH_TIEN_THEO_NGAY"], drRight["TIEN_GIO"], drRight["THANH_TIEN"], drRight["CK_PHANTRAM"], drRight["CK_TIEN"], 
                                                      drRight["VAT_PHANTRAM"], drRight["VAT_TIEN"], drRight["TTIEP_PHANTRAM"], drRight["TTIEP_TIEN"], drRight["PHU_THU_PHANTRAM"], 
                                                      drRight["PHU_THU"], drRight["TONG_TIEN"], drRight["GHI_CHU"], Variable.ngay_lamviec },
                                                      ref ioutput
                                                      );
                    if (irt < 1)
                    {
                        LPV_POS.Module.MessageBox_LPV.Show("Lưu không thành công");
                        return;
                    }
                    if (BH_PHIEU_MA2.IndexOf("--") >= 0)
                    {
                        BH_PHIEU_MA2 = ioutput + "";
                        drRight["OBJID"] = BH_PHIEU_MA2;
                    }
                }
                #endregion

                #region "   INSERT/UPDATE   BH_PHIEU_CT_TMP"
                DataTable tbLeftGrd = (DataTable)gridControlLeft.DataSource;
                #region "   tbLeftGrd"
                foreach (DataRow dr in tbLeftGrd.Rows)
                {
                    irt = othuvien.SP_Update("sp_mh_banhang",
                                    new string[] { "@flag", "@BH_PHIEU_MA",
                                                    "@OBJID", "@MAHH", "@DON_GIA", 
                                                    "@SO_LUONG", "@CHIETKHAU_PHANTRAM", "@CHIETKHAU_TIEN", 
                                                    "@THANH_TIEN","@GHI_CHU","@NGAY_TINH_GIO" },
                                    new object[] { 15, BH_PHIEU_MA,
                                                    dr["OBJID"],dr["MAHH"],dr["DON_GIA"],
                                                    dr["SO_LUONG"],dr["CHIETKHAU_PHANTRAM"],dr["CHIETKHAU_TIEN"],
                                                    dr["THANH_TIEN"],dr["GHI_CHU"],dr["NGAY_TINH_GIO"]}); 
                    if (irt < 1)
                        return;
                    dr["OBJID"] = irt;
                }
                #endregion

                DataTable tbRightGrd = (DataTable)gridControlRight.DataSource;
                #region "   tbRightGrd"
                foreach (DataRow dr in tbRightGrd.Rows)
                {
                    irt = othuvien.SP_Update("sp_mh_banhang",
                                    new string[] { "@flag", "@BH_PHIEU_MA",
                                                    "@OBJID", "@MAHH", "@DON_GIA", 
                                                    "@SO_LUONG", "@CHIETKHAU_PHANTRAM", "@CHIETKHAU_TIEN", 
                                                    "@THANH_TIEN","GHI_CHU","NGAY_TINH_GIO" },
                                    new object[] { 15, BH_PHIEU_MA2,
                                                    dr["OBJID"],dr["MAHH"],dr["DON_GIA"],
                                                    dr["SO_LUONG"],dr["CHIETKHAU_PHANTRAM"],dr["CHIETKHAU_TIEN"],
                                                    dr["THANH_TIEN"],dr["GHI_CHU"],dr["NGAY_TINH_GIO"]});
                    if (irt < 1)
                        return;
                    dr["OBJID"] = irt;
                }
                #endregion
                #endregion

                string sSQL = "";               
                #region "   tbDeleteLeft items"
                if (tbDeleteLeft!=null)
                    foreach (DataRow dr in tbDeleteLeft.Rows)
                    {
                        if (tbLeftGrd.Select("OBJID = " + dr["OBJID"] + "").Length == 0 && tbRightGrd.Select("OBJID = '" + dr["OBJID"] + "'").Length == 0)
                        {
                            sSQL = "DELETE FROM BH_PHIEU_CT_TMP WHERE OBJID LIKE '" + dr["OBJID"] + "' ";
                            irt = othuvien.SP_Update("SP_EXECUTEsql", new string[] { "@sSQK" }, new object[] { sSQL });
                        }
                    }
                #endregion

                #region "   tbDeleteRight items"
                if (tbDeleteRight != null)
                    foreach (DataRow dr in tbDeleteRight.Rows)
                    {
                        if (tbLeftGrd.Select("OBJID = " + dr["OBJID"] + "").Length == 0 && tbRightGrd.Select("OBJID = '" + dr["OBJID"] + "'").Length == 0)
                        {
                            sSQL = "DELETE FROM BH_PHIEU_CT_TMP WHERE OBJID = " + dr["OBJID"] + " ";
                            irt = othuvien.SP_Update("SP_EXECUTEsql", new string[] { "@sSQK" }, new object[] { sSQL });
                        }
                    }
                #endregion

                #region "   Update TRANG_THAI"
                irt = othuvien.SP_Update("sp_mh_banhang",
                                    new string[] { "@flag", "@BH_PHIEU_MA", "@BH_PHIEU_MA2" },
                                    new object[] { 16, BH_PHIEU_MA, BH_PHIEU_MA2 });
                
                if (irt < 1)
                    return;
                #endregion

                if (irt == 1)
                {
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
            }

        }
        #endregion

        #region "   cboPhieuLeft_SelectedIndexChanged"
        private void cboPhieuLeft_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (bLoadForm)
            {
                bLoadForm = false;
                BH_PHIEU_MA = cboPhieuLeft._GetselectedID();
                this.ShowData_tbLeft();
                bLoadForm = true;
                this.setAnHienButton();
            }
        }
        #endregion

        #region "   cboPhieuRight_SelectedIndexChanged"
        private void cboPhieuRight_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (bLoadForm)
            {
                bLoadForm = false;
                BH_PHIEU_MA2 = cboPhieuRight._GetselectedID();
                if (BH_PHIEU_MA2.IndexOf("--") >= 0)
                { // them PHIEU moi
                    DataTable tbPhieu = ((DataTable)cboPhieuRight.Datasource).Copy();
                    //9999

                }
                this.ShowData_tbRight();
                bLoadForm = true;
                this.setAnHienButton();
            }
        }
        #endregion

        #region "   setAnHienButton"
        void setAnHienButton()
        {
            btnThucHien.Enabled = ((BH_PHIEU_MA != BH_PHIEU_MA2) && BH_PHIEU_MA2 != "" && (gridViewLeft.RowCount > 0 || gridViewRight.RowCount > 0));
            btnGo.Enabled = btnThucHien.Enabled;
            btnBack.Enabled = btnThucHien.Enabled;
            btnGo1.Enabled = btnThucHien.Enabled;
            btnBack1.Enabled = btnThucHien.Enabled;

        }
        #endregion

        #region "   btnGo_Click"
        private void btnGo_Click(object sender, EventArgs e)
        {
            if (BH_PHIEU_MA != "" && BH_PHIEU_MA2 != "")
            {
                DataTable tbLeft = (DataTable)gridControlLeft.DataSource;
                DataTable tbRight = (DataTable)gridControlRight.DataSource;
                DataRow drLeft = (DataRow)gridViewLeft.GetDataRow(gridViewLeft.FocusedRowHandle);
                if (drLeft != null)
                {
                    float SO_LUONGLeft = 0;
                    float.TryParse(drLeft["SO_LUONG"] + "", out SO_LUONGLeft);//
                    this.TachGop(tbLeft, tbRight, drLeft, btnGo.Tag+"", SO_LUONGLeft);
                }
            }
        }
        #endregion

        #region "   btnBack_Click"
        private void btnBack_Click(object sender, EventArgs e)
        {
            if (BH_PHIEU_MA != "" && BH_PHIEU_MA2 != "")
            {
                DataTable tbRight = (DataTable)gridControlRight.DataSource;
                DataTable tbLeft = (DataTable)gridControlLeft.DataSource;
                DataRow drRight = (DataRow)gridViewRight.GetDataRow(gridViewRight.FocusedRowHandle);
                if (drRight != null)
                {
                    float SO_LUONGR = 0;
                    float.TryParse(drRight["SO_LUONG"] + "", out SO_LUONGR);//
                    this.TachGop(tbRight, tbLeft, drRight, btnBack.Tag+"", SO_LUONGR);
                }               
            }
        }
        #endregion

        #region "   btnGo1_Click"
        private void btnGo1_Click(object sender, EventArgs e)
        {
            if (BH_PHIEU_MA != "" && BH_PHIEU_MA2 != "")
            {
                DataTable tbLeft = (DataTable)gridControlLeft.DataSource;
                DataTable tbRight = (DataTable)gridControlRight.DataSource;
                DataRow drLeft = (DataRow)gridViewLeft.GetDataRow(gridViewLeft.FocusedRowHandle);
                if (drLeft != null)
                {
                    float SO_LUONGR = 0;
                    float.TryParse(drLeft["SO_LUONG"] + "", out SO_LUONGR);//
                    if (SO_LUONGR > 1)
                        SO_LUONGR = 1;
                    this.TachGop(tbLeft, tbRight, drLeft, btnGo1.Tag+"", SO_LUONGR);
                }
            }
        }
        #endregion

        #region "   btnBack1_Click"
        private void btnBack1_Click(object sender, EventArgs e)
        {
            if (BH_PHIEU_MA != "" && BH_PHIEU_MA2 != "")
            {
                DataTable tbRight = (DataTable)gridControlRight.DataSource;
                DataTable tbLeft = (DataTable)gridControlLeft.DataSource;
                DataRow drRight = (DataRow)gridViewRight.GetDataRow(gridViewRight.FocusedRowHandle);
                if (drRight != null)
                {
                    float SO_LUONGR = 0;
                    float.TryParse(drRight["SO_LUONG"] + "", out SO_LUONGR);//
                    if (SO_LUONGR > 1)
                        SO_LUONGR = 1;
                    this.TachGop(tbRight, tbLeft, drRight, btnBack1.Tag + "", SO_LUONGR);
                }
            }
        }
        #endregion

        #region "   TachGop"
        void TachGop(DataTable tbDataRemove, DataTable tbDataAdd, DataRow dr, string strDEL_LR, float SO_LUONG_Tru)
        {
            string OBJID = dr["OBJID"] + "";
            string MAHH = dr["MAHH"] + "";
            if (MAHH != "")
            {
                string Mon = dr["OBJNAME"] + "";
                float SO_LUONG = 0;                
                ///////////////////////Add
                if (tbDataAdd.Select("MAHH LIKE '" + MAHH + "'").Length == 0)
                {//Add.New                    
                    DataRow drAddTmp = tbDataAdd.NewRow();
                    drAddTmp.ItemArray = dr.ItemArray;
                    drAddTmp["SO_LUONG"] = SO_LUONG_Tru;
                    drAddTmp["OBJID"] = "-1";
                    tbDataAdd.Rows.Add(drAddTmp);
                }
                else
                {//Add.Exists
                    DataRow drAddTmp = (DataRow)tbDataAdd.Select("MAHH LIKE '" + MAHH + "'")[0];
                    float.TryParse(drAddTmp["SO_LUONG"] + "", out SO_LUONG);
                    drAddTmp["SO_LUONG"] = SO_LUONG + SO_LUONG_Tru;
                }

                ///////////////////////Remove
                foreach (DataRow drDel in tbDataRemove.Rows)
                    if (drDel["OBJID"] + "" == OBJID)
                    {
                        float.TryParse(drDel["SO_LUONG"] + "", out SO_LUONG);
                        if (SO_LUONG <= SO_LUONG_Tru)
                        {
                            if (strDEL_LR.IndexOf("R")>=0)
                            {
                                if (tbDeleteRight == null)
                                    tbDeleteRight = tbDataAdd.Clone();
                                DataRow drTmp = tbDeleteRight.NewRow();
                                drTmp.ItemArray = drDel.ItemArray;
                                tbDeleteRight.Rows.Add(drTmp);
                            }
                            else
                            {
                                if (tbDeleteLeft == null)
                                    tbDeleteLeft = tbDataAdd.Clone();
                                DataRow drTmp = tbDeleteLeft.NewRow();
                                drTmp.ItemArray = drDel.ItemArray;
                                tbDeleteLeft.Rows.Add(drTmp);
                            }
                            tbDataRemove.Rows.Remove(drDel);
                        }
                        else
                        {
                            float SLTmp = SO_LUONG - SO_LUONG_Tru;
                            SLTmp = (float)(Math.Round((double)SLTmp, 2));
                            drDel["SO_LUONG"] = SLTmp;
                        }
                        break;
                    }
                gridControlLeft.Refresh();
                gridControlRight.Refresh();
            }
        }
        #endregion

        #region "   TinhTongTien"
        void RefreshTable()
        {
            //////////////////
            this.TinhTongTien((DataTable)gridControlLeft.DataSource);
            this.TinhTongTien((DataTable)gridControlLeft.DataSource);

            //////////////////            

            if (BH_PHIEU_MA2.IndexOf("--") >= 0)
            {
                DataRow drLeft = null;
                DataRow drRight = null;
                if (((DataTable)cboPhieuLeft.Datasource).Select("OBJID LIKE '" + BH_PHIEU_MA + "'").Length > 0)
                    drLeft = ((DataTable)cboPhieuLeft.Datasource).Select("OBJID LIKE '" + BH_PHIEU_MA + "'")[0];

                if (((DataTable)cboPhieuRight.Datasource).Select("OBJID LIKE '" + BH_PHIEU_MA2 + "'").Length > 0)
                    drRight = ((DataTable)cboPhieuRight.Datasource).Select("OBJID LIKE '" + BH_PHIEU_MA2 + "'")[0];
                if (drLeft != null && drRight != null)
                { //Phieu.New()
                    drRight.ItemArray = drLeft.ItemArray;
                    drRight["OBJID"] = BH_PHIEU_MA2;
                }
            }
        }

        void TinhTongTien(DataTable _tbBH_PHIEU_CT_TMP)
        {
            float iSO_LUONG, iDON_GIA, iCHIETKHAU_TIEN, iVAT_TIEN;
            foreach (DataRow dr in _tbBH_PHIEU_CT_TMP.Select("MAHH NOT LIKE 'Tien_Gio'"))
            {
                if (dr["MAHH"] + "" != "Tien_Gio")
                {
                    float.TryParse(dr["SO_LUONG"] + "", out iSO_LUONG);
                    float.TryParse(dr["DON_GIA"] + "", out iDON_GIA);
                    float.TryParse(dr["CHIETKHAU_TIEN"] + "", out iCHIETKHAU_TIEN);
                    float.TryParse(dr["VAT_TIEN"] + "", out iVAT_TIEN);
                    dr["THANH_TIEN"] = iSO_LUONG * iDON_GIA - iCHIETKHAU_TIEN + iVAT_TIEN;
                }
                //break;
            }
        }
        #endregion
    }
}